package com.xmhmyh.generalframework.common.entity;

import com.xmhmyh.generalframework.common.enums.ResponseCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Author: 于丁
 * @Description: 同意的请求返回
 * @DateTime: 2020/7/21 4:07 下午
 * @Params:
 * @Return
 */
@ApiModel(value = "通用返回数据")
@Data
public class Response {
    /**
     * 返回状态
     **/
    @ApiModelProperty(value = "返回状态")
    private Integer code;
    /**
     * 返回消息
     **/
    @ApiModelProperty(value = "返回消息")
    private String msg;
    /**
     * 返回data
     **/
    @ApiModelProperty(value = "返回data")
    private Object data;


    public Response(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Response(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * @Author: 于丁
     * @Description: 请求成功
     * @DateTime: 2020/7/21 4:47 下午
     * @Params: data 返回前端的值
     * @Return
     */
    public static Response success(Object data) {
        return new Response(ResponseCode.SUCCESS.getValue(), ResponseCode.SUCCESS.getLabel(), data);
    }

    public static Response success() {
        return new Response(ResponseCode.SUCCESS.getValue(), ResponseCode.SUCCESS.getLabel());
    }

    public static Response fail(ResponseCode responseCode) {
        return new Response(responseCode.getValue(), responseCode.getLabel());
    }

    public static Response fail(String msg) {
        return new Response(ResponseCode.FAIL.getValue(), msg);
    }

}
